package cn.edu.hziee;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

public class ServletDemo3 extends HttpServlet {
    private ServletConfig config;
    @Override
    public void init(ServletConfig config) throws ServletException {
        this.config = config;
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out =response.getWriter();
//      String encoding = config.getInitParameter("encoding");            /*法1：*/
//        String title = config.getInitParameter("title");

//        out.print(encoding+title);
        Enumeration<String> em = config.getInitParameterNames();      /*法2：*/
        while(em.hasMoreElements()){
            String param = em.nextElement();
            String content = config.getInitParameter(param);
            out.print(param+":"+content);
            out.print("<br>");
        }
    }
}
